@model ProductModel

@using Telerik.Web.Mvc.UI;
@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)
@Html.Telerik().TabStrip().Name("product-edit").Items(x =>
{
    x.Add().Text(T("Admin.Catalog.Products.Info").Text).Content(TabInfo().ToHtmlString()).Selected(true);
    x.Add().Text(T("Admin.Common.SEO").Text).Content(TabSeo().ToHtmlString());
    if (Model.Id > 0)
    {
        x.Add().Text(T("Admin.Catalog.Products.Variants").Text).Content(TabVariants().ToHtmlString());
    }
    else
    {
        x.Add().Text(T("Admin.Catalog.Products.FirstVariant").Text).Content(TabFirstVariantInfo().ToHtmlString());
    }

    if (Model.IsAdmin)
    {
        x.Add().Text(T("Admin.Catalog.Products.RelatedProducts").Text).Content(TabRelatedProducts().ToHtmlString());
        x.Add().Text(T("Admin.Catalog.Products.CrossSells").Text).Content(TabCrossSells().ToHtmlString());
    }

    x.Add().Text(T("Admin.Catalog.Products.Pictures").Text).Content(TabPictures().ToHtmlString());
    x.Add().Text(T("Admin.Catalog.Products.SpecificationAttributes").Text).Content(TabSpecificationAttributes().ToHtmlString());
    if (Model.IsAdmin)
    {
        x.Add().Text(T("Admin.Catalog.Products.Categories").Text).Content(TabCategories().ToHtmlString());
        x.Add().Text(T("Admin.Catalog.Products.Acl").Text).Content(TabAcl().ToHtmlString());
    }

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "product-edit"));
})
@helper TabInfo()
{
    @Html.HiddenFor(model => model.ProductTemplateId)
    @(Html.LocalizedEditor<ProductModel, ProductLocalizedModel>("product-info-localized",
    @<table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].Name):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => Model.Locales[item].Name)
                @Html.ValidationMessageFor(model => model.Locales[item].Name)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].ShortDescription):
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.Locales[item].ShortDescription)
                @Html.ValidationMessageFor(model => model.Locales[item].ShortDescription)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].FullDescription):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Locales[item].FullDescription, "RichEditor")
                @Html.ValidationMessageFor(model => model.Locales[item].FullDescription)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Html.HiddenFor(model => model.Locales[item].LanguageId)
            </td>
        </tr>
    </table>
                ,
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Name):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => model.Name)
                            @Html.ValidationMessageFor(model => model.Name)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.ShortDescription):
                        </td>
                        <td class="adminData">
                            @Html.TextAreaFor(x => x.ShortDescription)
                            @Html.ValidationMessageFor(model => model.ShortDescription)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.FullDescription):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(x => x.FullDescription, "RichEditor")
                            @Html.ValidationMessageFor(model => model.FullDescription)
                        </td>
                    </tr>
                </table>
        ))
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AdminComment):
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.AdminComment)
                @Html.ValidationMessageFor(model => model.AdminComment)
            </td>
        </tr>
        @*@if (Model.IsCustomerStoreAdmin)
            {
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.ProductTemplateId):
                    </td>
                    <td class="adminData">
                        @Html.DropDownListFor(model => model.ProductTemplateId, Model.AvailableProductTemplates)
                        @Html.ValidationMessageFor(model => model.ProductTemplateId)

                    </td>
                </tr>
            }*@
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ShowOnHomePage):
            </td>
            <td class="adminData">
                @if (Model.IsAdmin)
                {
                    @Html.EditorFor(model => model.ShowOnHomePage)
                    @Html.ValidationMessageFor(model => model.ShowOnHomePage)
                }
                else
                {
                    @Html.DisplayTextFor(model => model.ShowOnHomePage)
                    @Html.HiddenFor(model => model.ShowOnHomePage)
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Published):
            </td>
            <td class="adminData">
                @if (Model.IsCustomerStoreAdmin)
                {
                    @Html.EditorFor(model => model.Published)
                    @Html.ValidationMessageFor(model => model.Published)
                }
                else
                {
                    @Html.DisplayTextFor(model => model.Published)
                    @Html.HiddenFor(model => model.Published)
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AllowCustomerReviews):
            </td>
            <td class="adminData">
                @if (Model.IsCustomerStoreAdmin)
                {
                    @Html.EditorFor(model => model.AllowCustomerReviews)
                    @Html.ValidationMessageFor(model => model.AllowCustomerReviews)
                }
                else
                {
                    @Html.DisplayTextFor(model => model.AllowCustomerReviews)
                    @Html.HiddenFor(model => model.AllowCustomerReviews)
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.StoreId):
            </td>
            <td class="adminData">
                @if (Model.IsCustomerStoreAdmin)
                {
                    <span>@Model.Store</span><br />
                    @(Html.Telerik().ComboBoxFor(model => model.StoreId)
                        .AutoFill(true)
                        .Value(Model.StoreId == 0 ? string.Empty : Model.StoreId.ToString())
                        .Filterable()
                        .DataBinding(binding => binding.Ajax().Select("StoreList", "Store", new { storeId = Model.StoreId, customerId = 0 })))
                }
                else
                {
                    @Html.HiddenFor(model => model.StoreId)
                    @Html.LabelForModel(Model.Store)
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AgeClass):
            </td>
            <td class="adminDate">
                @if(Model.IsAdmin)
                {
                    @Html.TextBoxFor(model => model.AgeClass);                    
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ShippingReturnTopicName)
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.ShippingReturnTopicName, Model.AvailableTopics);
            </td>
        </tr>
    </table>
}
@helper TabFirstVariantInfo()
{
    var dataDictFpv = new ViewDataDictionary();
    dataDictFpv.TemplateInfo.HtmlFieldPrefix = "FirstProductVariantModel";
    @Html.Partial("_ProductVariantInfo", Model.FirstProductVariantModel, dataDictFpv)
}
@helper TabSeo()
{
    @(Html.LocalizedEditor<ProductModel, ProductLocalizedModel>("product-seo-localized",
    @<table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].MetaKeywords):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Locales[item].MetaKeywords)
                @Html.ValidationMessageFor(model => model.Locales[item].MetaKeywords)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].MetaDescription):
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.Locales[item].MetaDescription)
                @Html.ValidationMessageFor(model => model.Locales[item].MetaDescription)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].MetaTitle):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Locales[item].MetaTitle)
                @Html.ValidationMessageFor(model => model.Locales[item].MetaTitle)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].SeName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Locales[item].SeName)
                @Html.ValidationMessageFor(model => model.Locales[item].SeName)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Html.HiddenFor(model => model.Locales[item].LanguageId)
            </td>
        </tr>
    </table>
               ,
            @<table class="adminContent">
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MetaKeywords):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.MetaKeywords)
                        @Html.ValidationMessageFor(model => model.MetaKeywords)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MetaDescription):
                    </td>
                    <td class="adminData">
                        @Html.TextAreaFor(x => x.MetaDescription)
                        @Html.ValidationMessageFor(model => model.MetaDescription)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.MetaTitle):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.MetaTitle)
                        @Html.ValidationMessageFor(model => model.MetaTitle)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.SeName):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(x => x.SeName)
                        @Html.ValidationMessageFor(model => model.SeName)
                    </td>
                </tr>
            </table>))
}
@helper TabVariants()
{
    @(Html.Telerik().Grid(Model.ProductVariantModels).Name("product-variants")
    .Columns(columns =>
    {
        columns.Bound(x => x.Name);
        columns.Bound(x => x.Sku);
        columns.Bound(x => x.Price).Format("{0:G29}");
        columns.Bound(x => x.DisplayOrder)
            .Centered();
        columns.Bound(x => x.RegionName);
        columns.Bound(x => x.IsOpenBoxProductVariant)
            .Template(
            @<img alt="" src="@Url.Content("~/subsites/Administration/Content/images/active-" + item.IsOpenBoxProductVariant.ToString().ToLowerInvariant() + ".gif")" />
            )
            .ClientTemplate("<img alt='' src='" + Url.Content("~/subsites/Administration/Content/images/") + "active-<#= IsOpenBoxProductVariant #>.gif' />")
            .Centered()
            .Width(100);
        columns.Bound(x => x.RackLocation);
        columns.Bound(x => x.Published)
            .Template(
            @<img alt="" src="@Url.Content("~/subsites/Administration/Content/images/active-" + item.Published.ToString().ToLowerInvariant() + ".gif")" />
            )
            .ClientTemplate("<img alt='' src='" + Url.Content("~/subsites/Administration/Content/images/") + "active-<#= Published #>.gif' />")
            .Centered()
            .Width(100);
        columns.Template((x) => Html.ActionLink(T("Admin.Common.Edit").ToString(), "Edit", "ProductVariant", new { id = x.Id }, new { })).Title(T("Admin.Common.Edit").ToString());
    })
                                    .Footer(false))
    <div class="clear">
    </div>
    <a href="@Url.Action("Create", "ProductVariant", new { productId = Model.Id })" class="t-button">@T("Admin.Catalog.Products.Variants.AddNew")</a>
}
@helper TabCategories()
{
    if (Model.Id > 0 && Model.IsAdmin)
    {
        if (Model.NumberOfAvailableCategories > 0)
        {
            @(Html.Telerik().Grid<ProductModel.ProductCategoryModel>()
                    .Name("productcategories-grid")
                       .DataKeys(keys =>
                       {
                           keys.Add(x => x.Id);
                       })
                       .DataBinding(dataBinding =>
                       {
                           dataBinding.Ajax()
                               .Select("ProductCategoryList", "Product", new { productId = Model.Id })
                               .Insert("ProductCategoryInsert", "Product", new { productId = Model.Id })
                               .Update("ProductCategoryUpdate", "Product", new { productId = Model.Id })
                               .Delete("ProductCategoryDelete", "Product");
                       })
                       .Columns(columns =>
                       {
                           columns.Bound(x => x.Category)
                               .Width(500)
                               .Centered();
                           columns.Bound(x => x.IsFeaturedProduct)
                               .Width(100)
                               .Centered();
                           columns.Bound(x => x.DisplayOrder)
                               .Width(100);
                           columns.Command(commands =>
                           {
                               commands.Edit().Text(T("Admin.Common.Edit").Text);
                               commands.Delete().Text(T("Admin.Common.Delete").Text);
                           })
                           .Width(180);
                       })
                       .ToolBar(commands => commands.Insert())
                       .ClientEvents(events => events.OnEdit("onProductCategoryEdit"))
                       .EnableCustomBinding(true))

            <script type="text/javascript">
                function onProductCategoryEdit(e) {
                    $(e.form).find('#Category').data('tDropDownList').select(function (dataItem) {
                        return dataItem.Value == e.dataItem['CategoryId'];
                    });
                }
            </script>
        }
        else
        {
            @T("Admin.Catalog.Products.Categories.NoCategoriesAvailable")
        }
    }
    else
    {
        @T("Admin.Catalog.Products.Categories.SaveBeforeEdit")
    }

}
@helper TabRelatedProducts()
{
    if (Model.Id > 0 && Model.IsAdmin)
    {
        <table class="adminContent">
            <tr>
                <td>
                    @(Html.Telerik().Grid<ProductModel.RelatedProductModel>()
                            .Name("relatedproducts-grid")
                            .DataKeys(keys =>
                            {
                                keys.Add(x => x.Id);
                            })
                            .DataBinding(dataBinding =>
                            {
                                dataBinding.Ajax()
                                    .Select("RelatedProductList", "Product", new { productId = Model.Id })
                                    .Update("RelatedProductUpdate", "Product")
                                    .Delete("RelatedProductDelete", "Product");
                            })
                            .Columns(columns =>
                            {
                                columns.Bound(x => x.Product2Name)
                                    .Width(500)
                                    .ReadOnly();
                                columns.Bound(x => x.DisplayOrder)
                                    .Width(100)
                                    .Centered();
                                columns.Command(commands =>
                                {
                                    commands.Edit().Text(T("Admin.Common.Edit").Text);
                                    commands.Delete().Text(T("Admin.Common.Delete").Text);
                                })
                                .Width(180);
                            })
                            .EnableCustomBinding(true))
                </td>
            </tr>
            <tr>
                <td width="100%">
                    <input type="submit" id="btnAddNewRelatedProduct" name="btnAddNewRelatedProduct" value="@T("Admin.Catalog.Products.RelatedProducts.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("RelatedProductAddPopup", "Product", new { productId = Model.Id, btnId = "btnRefreshRelatedProducts", formId = "product-form" }))    ', 800, 700, true); return false;" class="t-button" />
                    <input type="submit" id="btnRefreshRelatedProducts" name="btnRefreshRelatedProducts" style="display: none" />
                    <script type="text/javascript">
                        $(document).ready(function () {
                            $('#btnRefreshRelatedProducts').click(function () {
                                //refresh grid
                                var optionsGrid = $("#relatedproducts-grid");
                                optionsGrid.data('tGrid').ajaxRequest();

                                //return false to don't reload a page
                                return false;
                            });
                        });
                    </script>
                </td>
            </tr>
        </table>
    }
    else
    {
        @T("Admin.Catalog.Products.RelatedProducts.SaveBeforeEdit")
    }

}
@helper TabCrossSells()
{
    if (Model.Id > 0 && Model.IsAdmin)
    {
        <table class="adminContent">
            <tr>
                <td>
                    @(Html.Telerik().Grid<ProductModel.CrossSellProductModel>()
                .Name("crosssellproducts-grid")
                    .DataKeys(keys =>
                    {
                        keys.Add(x => x.Id);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax()
                            .Select("CrossSellProductList", "Product", new { productId = Model.Id })
                            .Delete("CrossSellProductDelete", "Product");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Product2Name)
                            .Width(500)
                            .ReadOnly();
                        columns.Command(commands =>
                        {
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                        })
                        .Title(T("Admin.Common.Delete").Text).Width(50);
                    })
                    .EnableCustomBinding(true))
                </td>
            </tr>
            <tr>
                <td width="100%">
                    <input type="submit" id="btnAddNewCrossSellProduct" name="btnAddNewCrossSellProduct" value="@T("Admin.Catalog.Products.CrossSells.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("CrossSellProductAddPopup", "Product", new { productId = Model.Id, btnId = "btnRefreshCrossSellProducts", formId = "product-form" }))    ', 800, 700, true); return false;" class="t-button" />
                    <input type="submit" id="btnRefreshCrossSellProducts" name="btnRefreshCrossSellProducts" style="display: none" />
                    <script type="text/javascript">
                        $(document).ready(function () {
                            $('#btnRefreshCrossSellProducts').click(function () {
                                //refresh grid
                                var optionsGrid = $("#crosssellproducts-grid");
                                optionsGrid.data('tGrid').ajaxRequest();

                                //return false to don't reload a page
                                return false;
                            });
                        });
                    </script>
                </td>
            </tr>
        </table>
    }
    else
    {
        @T("Admin.Catalog.Products.CrossSells.SaveBeforeEdit")
    }

}
@helper TabPictures()
{
    if (Model.Id > 0)
    {
        <div>
            @(Html.Telerik().Grid<ProductModel.ProductPictureModel>()
                    .Name("productpictures-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.PictureUrl)
                            .ClientTemplate("<a href='<#= PictureUrl #>' target='_blank'><img alt='<#= PictureId #>' src='<#= PictureUrl #>' width='150' /><a/>")
                            .ReadOnly();
                        columns.Bound(x => x.DisplayOrder);
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                        });

                    })
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("ProductPictureList", "Product", new { productId = Model.Id })
                            .Update("ProductPictureUpdate", "Product")
                            .Delete("ProductPictureDelete", "Product");
                    })
                    .EnableCustomBinding(true))
        </div>
        <p>
            <strong>@T("Admin.Catalog.Products.Pictures.AddNew")</strong>
        </p>
        <script type="text/javascript">

            $(document).ready(function () {
                $('#addProductPicture').click(function () {
                    var pictureId = $("#@Html.FieldIdFor(model => model.AddPictureModel.PictureId)").val();
                    var displayOrder = $("#@Html.FieldIdFor(model => model.AddPictureModel.DisplayOrder)").val();

                    if (pictureId == 0) {
                        alert('Upload picture first');
                        return;
                    }

                    $('#addProductPicture').attr('disabled', true);
                    $.ajax({
                        cache:false,
                        type: "POST",
                        url: "@(Url.Action("ProductPictureAdd", "Product"))",
                        data: { "pictureId": pictureId, "displayOrder": displayOrder, "productId": @Model.Id },
                        success: function (data) {
                            var productpicturesGrid = $("#productpictures-grid");
                            productpicturesGrid.data('tGrid').ajaxRequest();
                            $('#addProductPicture').attr('disabled', false);
                        },
                        error:function (xhr, ajaxOptions, thrownError){
                            alert('Failed to add product picture.');
                            $('#addProductPicture').attr('disabled', false);
                        }
                    });
                });
            });
        </script>
        <table class="adminContent">
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.AddPictureModel.PictureId):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.AddPictureModel.PictureId)
                    @Html.ValidationMessageFor(model => model.AddPictureModel.PictureId)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.AddPictureModel.DisplayOrder):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.AddPictureModel.DisplayOrder)
                    @Html.ValidationMessageFor(model => model.AddPictureModel.DisplayOrder)
                </td>
            </tr>
            <tr>
                <td colspan="2" align="left">
                    <input type="button" id="addProductPicture" class="t-button" value="@T("Admin.Catalog.Products.Pictures.AddButton")" />
                </td>
            </tr>
        </table>
    }
    else
    {
        @T("Admin.Catalog.Products.Pictures.SaveBeforeEdit")
    }
}

@helper TabSpecificationAttributes()
{
    if (Model.Id > 0)
    {
        /*hide "add spec" table if no attributes are defined*/
        if (Model.AddSpecificationAttributeModel.AvailableAttributes.Count > 0)
        {
            <div>
                @(Html.Telerik().Grid<ProductSpecificationAttributeModel>()
                    .Name("specificationattributes-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("psaId");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.SpecificationAttributeName).Width(200).ReadOnly();
                        columns.Bound(x => x.SpecificationAttributeOptionName).Width(200).ReadOnly();
                        columns.Bound(x => x.AllowFiltering).Width(100);
                        columns.Bound(x => x.ShowOnProductPage).Width(100);
                        columns.Bound(x => x.DisplayOrder).Width(100);
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                        }).Width(180);

                    })
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("ProductSpecAttrList", "Product", new { productId = Model.Id })
                            .Update("ProductSpecAttrUpdate", "Product")
                            .Delete("ProductSpecAttrDelete", "Product");
                    })
                    .EnableCustomBinding(true))
            </div>
            <p>
                <strong>@T("Admin.Catalog.Products.SpecificationAttributes.AddNew")</strong>
            </p>
            <script type="text/javascript">
                $(function() {
                    $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId)").change(function() {
                        var selectedItem = $(this).val();
                        var ddlSpecOptions = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId)")
                        $.ajax({
                            cache:false,
                            type: "GET",
                            url: "@(Url.Action("GetOptionsByAttributeId", "SpecificationAttribute"))",
                            data: { "attributeId": selectedItem },
                            success: function (data) {
                                ddlSpecOptions.html('');
                                $.each(data, function(id, option) {
                                    ddlSpecOptions.append($('<option></option>').val(option.id).html(option.name));
                                });
                            },
                            error:function (xhr, ajaxOptions, thrownError){
                                alert('Failed to retrieve specification options.');
                            }
                        });
                    });
                });

                $(document).ready(function () {
                    $('#addProductSpec').click(function () {
                        var specificationAttributeOptionId = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId)").val();
                        var allowFiltering = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.AllowFiltering)").is(':checked');
                        var showOnProductPage = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage)").is(':checked');
                        var displayOrder = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.DisplayOrder)").val();

                        $('#addProductSpec').attr('disabled', true);
                        $.ajax({
                            cache:false,
                            type: "POST",
                            url: "@(Url.Action("ProductSpecificationAttributeAdd", "Product"))",
                            data: { "specificationAttributeOptionId": specificationAttributeOptionId, "allowFiltering": allowFiltering, "showOnProductPage": showOnProductPage, "displayOrder": displayOrder, "productId": @Model.Id },
                            success: function (data) {
                                var specificationAttributesGrid = $("#specificationattributes-grid");
                                specificationAttributesGrid.data('tGrid').ajaxRequest();
                                $('#addProductSpec').attr('disabled', false);
                            },
                            error:function (xhr, ajaxOptions, thrownError){
                                alert('Failed to add specification attribute.');
                                $('#addProductSpec').attr('disabled', false);
                            }
                        });
                    });
                });
            </script>
            <table class="adminContent">
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId):
                    </td>
                    <td class="adminData">
                        @Html.DropDownListFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId, Model.AddSpecificationAttributeModel.AvailableAttributes)
                        @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId):
                    </td>
                    <td class="adminData">
                        @Html.DropDownListFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId, Model.AddSpecificationAttributeModel.AvailableOptions)
                        @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.AllowFiltering):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(model => model.AddSpecificationAttributeModel.AllowFiltering)
                        @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.AllowFiltering)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage)
                        @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.DisplayOrder):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(model => model.AddSpecificationAttributeModel.DisplayOrder)
                        @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.DisplayOrder)
                    </td>
                </tr>               
                <tr>
                    <td colspan="2" align="left">
                        <input type="button" id="addProductSpec" class="t-button" value="@T("Admin.Catalog.Products.SpecificationAttributes.AddButton")" />
                    </td>
                </tr>
            </table>
        }
        else
        {
            @T("Admin.Catalog.Products.SpecificationAttributes.NoAttributes")
        }
    }
    else
    {
        @T("Admin.Catalog.Products.SpecificationAttributes.SaveBeforeEdit")
    }
}
@helper TabAcl()
{
    if (Model.IsAdmin)
    {
        <script type="text/javascript">
            $(document).ready(function () {

                $("#@Html.FieldIdFor(model => model.SubjectToAcl)").click(toggleAcl);

                toggleAcl();
            });


            function toggleAcl() {
                if ($('#@Html.FieldIdFor(model => model.SubjectToAcl)').is(':checked')) {
                    $('#pnl-acl').show();
                }
                else {
                    $('#pnl-acl').hide();
                }
            }

        </script>
        <table class="adminContent">
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.SubjectToAcl):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.SubjectToAcl)
                    @Html.ValidationMessageFor(model => model.SubjectToAcl)
                </td>
            </tr>
            <tr id="pnl-acl">
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.AvailableCustomerRoles):
                </td>
                <td class="adminData">
                    @if (Model.AvailableCustomerRoles != null && Model.AvailableCustomerRoles.Count > 0)
                    {
                        foreach (var customerRole in Model.AvailableCustomerRoles)
                        {
                            <div>
                                <input type="checkbox" name="SelectedCustomerRoleIds" value="@customerRole.Id" checked="@(Model.SelectedCustomerRoleIds != null && Model.SelectedCustomerRoleIds.Contains(customerRole.Id))" />@customerRole.Name
                            </div>
                        }
                    }
                    else
                    {
                        <div>No customer roles defined</div>
                    }
                </td>
            </tr>
        </table>
    }
}